package com.link.wseller.mapper;

import com.link.wseller.domain.ProductInfo;
import org.apache.ibatis.jdbc.SQL;

public class ProductInfoSqlProvider {

    public String insertSelective(ProductInfo record) {
        SQL sql = new SQL();
        sql.INSERT_INTO("product_info");
        
        if (record.getProductId() != null) {
            sql.VALUES("product_id", "#{productId,jdbcType=VARCHAR}");
        }
        
        if (record.getProductName() != null) {
            sql.VALUES("product_name", "#{productName,jdbcType=VARCHAR}");
        }
        
        if (record.getProductPrice() != null) {
            sql.VALUES("product_price", "#{productPrice,jdbcType=DECIMAL}");
        }
        
        if (record.getProductStock() != null) {
            sql.VALUES("product_stock", "#{productStock,jdbcType=INTEGER}");
        }
        
        if (record.getProductDescription() != null) {
            sql.VALUES("product_description", "#{productDescription,jdbcType=VARCHAR}");
        }
        
        if (record.getProductIcon() != null) {
            sql.VALUES("product_icon", "#{productIcon,jdbcType=VARCHAR}");
        }
        
        if (record.getProductStatus() != null) {
            sql.VALUES("product_status", "#{productStatus,jdbcType=TINYINT}");
        }
        
        if (record.getCategoryType() != null) {
            sql.VALUES("category_type", "#{categoryType,jdbcType=INTEGER}");
        }
        
        if (record.getCreateTime() != null) {
            sql.VALUES("create_time", "#{createTime,jdbcType=TIMESTAMP}");
        }
        
        if (record.getUpdateTime() != null) {
            sql.VALUES("update_time", "#{updateTime,jdbcType=TIMESTAMP}");
        }
        
        return sql.toString();
    }

    public String updateByPrimaryKeySelective(ProductInfo record) {
        SQL sql = new SQL();
        sql.UPDATE("product_info");
        
        if (record.getProductName() != null) {
            sql.SET("product_name = #{productName,jdbcType=VARCHAR}");
        }
        
        if (record.getProductPrice() != null) {
            sql.SET("product_price = #{productPrice,jdbcType=DECIMAL}");
        }
        
        if (record.getProductStock() != null) {
            sql.SET("product_stock = #{productStock,jdbcType=INTEGER}");
        }
        
        if (record.getProductDescription() != null) {
            sql.SET("product_description = #{productDescription,jdbcType=VARCHAR}");
        }
        
        if (record.getProductIcon() != null) {
            sql.SET("product_icon = #{productIcon,jdbcType=VARCHAR}");
        }
        
        if (record.getProductStatus() != null) {
            sql.SET("product_status = #{productStatus,jdbcType=TINYINT}");
        }
        
        if (record.getCategoryType() != null) {
            sql.SET("category_type = #{categoryType,jdbcType=INTEGER}");
        }
        
        if (record.getCreateTime() != null) {
            sql.SET("create_time = #{createTime,jdbcType=TIMESTAMP}");
        }
        
        if (record.getUpdateTime() != null) {
            sql.SET("update_time = #{updateTime,jdbcType=TIMESTAMP}");
        }
        
        sql.WHERE("product_id = #{productId,jdbcType=VARCHAR}");
        
        return sql.toString();
    }
}